package com.gwclh.personnel.controller;


import cn.hutool.core.lang.Assert;
import cn.hutool.json.JSONArray;
import com.gwclh.personnel.bean.ResultVo;
import com.gwclh.personnel.common.annotation.OperLog;
import com.gwclh.personnel.common.constants.OperLogConstants;
import com.gwclh.personnel.domain.PageDomain;
import com.gwclh.personnel.entity.OperationLog;
import com.gwclh.personnel.service.IOperationLogService;
import com.gwclh.personnel.vo.operlogvo.OperLogVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 操作记录表
 前端控制器
 * </p>
 *
 * @author gzhhh
 * @since 2020-07-24
 */
@RestController
@RequestMapping("/operation-logs")
@Api(tags = "操作记录相关接口")
@Slf4j
@Validated
public class OperationLogController extends BaseController {

    @Autowired
    IOperationLogService operationLogService;

    @GetMapping("")
    @ApiOperation(value = "分页查询操作记录列表")
    @RequiresRoles({"ROLE_admin"})
    public ResultVo listOperLog(OperLogVo operLogVo, HttpServletRequest request){
        PageDomain pageDomain = getPageParams(request);
        return operationLogService.listOperLogs(pageDomain,operLogVo);
    }

    @DeleteMapping("")
    @ApiOperation(value = "批量删除操作记录")
    @RequiresRoles({"ROLE_admin"})
    @OperLog(operModule = OperLogConstants.OPER_LOG_MODULE_OPER_LOG,operType = OperLogConstants.OPER_LOG_DELETE,operDesc = "批量删除记录")
    @ApiImplicitParam(name = "ids",value = "操作记录id数组",dataType = "List",paramType = "body",required = true)
    public ResultVo delListOperLog(@RequestBody List<Long> ids){
//        log.warn(.toString());
        Assert.isTrue(operationLogService.removeByIds(ids),"删除失败");

        return ResultVo.success();
    }

}
